/*
* @example An iframe-based dialog with custom button handling logics.
*/
(function() {
    CKEDITOR.plugins.add('SilverlightImage',
    {
        requires: ['iframedialog'],
        init: function(editor) {
            var me = this;

            CKEDITOR.dialog.add('SilverlightImageDialog', function() {
                return {
                    title: 'Image Manager Dialog',
                    minWidth: 550,
                    minHeight:350,
                    contents:
                       [
                          {
                              id: 'iframe',
                              label: 'Image',
                              expand: true,
                              elements:
                                   [
                                      {
                                          type: 'html',
                                          id: 'pageSilverlightImage',
                                          label: 'Image Manager',
                                          style: 'width : 100%;',
                                          html: '<iframe src="' + me.path + 'dialogs/SilverlightImage.html" frameborder="0" name="iframeSilverlightImage" id="iframeSilverlightImage" allowtransparency="1" style="width:100%; height:400px;margin:0;padding:0;"></iframe>'
                                      }
                                   ]
                          }
                       ],
                    onOk: function() {
                        for (var i = 0; i < window.frames.length; i++) {
                            if (window.frames[i].name == 'iframeSilverlightImage') {
                                var filename = window.frames[i].document.getElementById("SelectedImage").value;
                                var Width = window.frames[i].document.getElementById("Width").value;
                                var Heigth = window.frames[i].document.getElementById("Height").value;
                                var url = "/Service/Thumbnail/" + Width + "/" + Heigth + "/ContentImages/" + filename;
                                var alt = window.frames[i].document.getElementById("Alt").value;
                            }
                        }
                        editor.insertHtml('<img src="' + url + '" alt="' + alt + '"/>');
                    }
                };
            });

            editor.addCommand('SilverlightImage', new CKEDITOR.dialogCommand('SilverlightImageDialog'));

            editor.ui.addButton('SilverlightImage',
            {
                label: 'Image Manager',
                command: 'SilverlightImage',
                icon: this.path + 'images/icon.gif'
            });
        }
    });
})();
